<?php
global $_W, $_GPC;
$uid = $_GPC['uid'];
$weid = $_W['uniacid'];
$lessonid = $_GPC['lid'];
if (empty($uid)) {
    return $this->getresult(1, '请先登录', array('code' => 3001, 'msg' => '请先登录'));
}
if (empty($lessonid)) {
    return $this->getresult(1, '请先选择课程', array('code' => 3001, 'msg' => '请先选择课程'));
}
/***校验token开始***/
if ($uid) {
    $token = $_GPC['token'];
    if (empty($token)) {
        return $this->getresult(1, '请重新登录', ['code' => 4001, 'msg' => '请重新登录']);
    }
    $token_result = $this->checktoken($uid, $token);
    if ($token_result == 1002) {
        return $this->getresult(1, '请重新登录', ['code' => 4002, 'msg' => '请重新登录']);
    } elseif ($token_result == 1003) {
        return $this->getresult(1, '请重新登录', ['code' => 4003, 'msg' => '请重新登录']);
    } elseif ($token_result == 1001) {
        //  更新token
        pdo_update($this->t_user_token, array('createtime' => time()), array('uid' => $uid, 'token' => $token, 'weid' => $_W['uniacid']));
    }
}
/***校验token结束***/
$types_config = array('1' => '判断题', '2' => '单选题', '3' => '多选题', '4' => '填空题');
$params = [':weid' => $weid, ':uid' => $uid, ':is_delete' => 1, ':lessonid' => $lessonid];
$falseList = pdo_fetchall("select fr.useranswer,p.id,p.type,p.question,p.thumb,p.answer,p.items,p.img_items,p.analysis,p.isimg from " . tablename('goouc_class_practice_false_record') . " fr LEFT JOIN " . tablename('goouc_class_practice') . " p ON fr.practiceid = p.id " . " where fr.weid = :weid AND fr.uid = :uid AND fr.is_delete = :is_delete AND fr.lessonid = :lessonid", $params);
foreach ($falseList as $k => &$v) {
    if ($v['thumb']) {
        $v['thumb'] = $this->getImgUrl($v['thumb']);
    }
    if ($v['type'] == 2 || $v['type'] == 3) {
        if ($v['items']) {
            $v['items'] = unserialize($v['items']);
        }
        if ($v['isimg'] == 1) {
            if ($v['img_items']) {
                $img_items = unserialize($v['img_items']);
                foreach ($img_items as &$vi) {
                    $vi['p'] = $this->getImgUrl($vi['p']);
                }
                $v['img_items'] = $img_items;
            }
        }
    }
}
return $this->getresult(0, '课程错题列表', ['code' => 200, 'falselists' => $falseList]);